import {ref,computed} from 'vue'
import {defineStore} from 'pinia'

// interface UserInfo {
//     name: string
//     age: number
// }
//
// interface State {
//     userList: UserInfo[]
//     user: UserInfo | null
// }

//选项式API Vu2 Option 对象
// export const useCounterStore = defineStore('counter',{
//     state: () => {
//         return { count: 0 }
//     },
//     actions: {
//         increment() {
//             this.count++;
//         }
//     }
// })

//组合式API Vue3 Setup 函数
export const useCounterStore = defineStore('counter',()=>{
    const count = ref(0)
    const doubleCount = computed(function () { return count.value * 2; })
    const increment = function () {
        count.value++;
    }

    const reset = function () {
        count.value = 0;
    }


    return {
        count: count,
        doubleCount: doubleCount,
        reset: reset,
        increment: increment
    }
})





